package alo.p6.work;

import alo.p6.BinaryTreeNode;

import java.util.LinkedList;
import java.util.Queue;

//二叉树最深结点查找
//只使用了层续遍历
public class DeepestNodeInBinaryTree {
    BinaryTreeNode deepestNodeInBinaryTree(BinaryTreeNode root){
        BinaryTreeNode temp=null;
        Queue<BinaryTreeNode> queue=new LinkedList<>();
        if (root==null) return temp;
        queue.offer(root);
        while (!queue.isEmpty()){
            temp=queue.poll();
            if (temp.getLeft()!=null) queue.offer(temp.getLeft());
            if (temp.getRight()!=null) queue.offer(temp.getRight());
        }
        return temp;
    }
}
